package com.siss.tenancy.user.config;



import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;

import java.util.Properties;

/**
 * mybatis mapper 扫描配置类
 *
 * @author ygw
 * @date 2017年7月11日
 * @since 1.7
 */
@Configuration
@AutoConfigureAfter(MybatisConfiguration.class)
public class MapperConfiguration {


    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer(Environment environment, Myproperties myproperties) {

        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
        mapperScannerConfigurer.setBasePackage(myproperties.getBasePackage());
        //UUID回显     "SELECT UUID()" String.valueOf(IdWorker.getWorkId())
        Properties propertiesMapper = new Properties();
        propertiesMapper.setProperty("mappers", "tk.mybatis.mapper.common.Mapper");
        propertiesMapper.setProperty("IDENTITY", "SELECT UPPER(REPLACE(UUID(),'-', '')) ");
        propertiesMapper.setProperty("ORDER", "BEFORE");
        mapperScannerConfigurer.setProperties(propertiesMapper);

        return mapperScannerConfigurer;
    }


}